<template>
	<view class="pages">
		<view class="pages_title">
			{{$t('index.Welcome')}} !
		</view>
		<view class="pages_tips">
			{{$t('dengtpsss')}}?
		</view>
		<u-button type="primary" :text="$t('ScanNow')"
			:customStyle="{width:'100%',height:'80rpx',backgroundColor:'#273562',color:'#fff',margin:'330rpx auto 0rpx',fontWeight:'700',border:'none'}"
			@click="zhuce()"></u-button>
		<u-button type="primary" :text="$t('Skip')"
			:customStyle="{width:'100%',height:'80rpx',backgroundColor:'#D9D9D9',color:'#333',margin:'20px auto 0rpx', fontWeight:'700',border:'none'}"
			@click="$next('./register1')"></u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			zhuce(val) {
				var that = this;
				wx.scanCode({
					onlyFromCamera: false, // 只允许从相机扫码
					success(res) {
						uni.showLoading({
							mask: true
						})
						function getUrlParams(url) {
						    // 通过 ? 分割获取后面的参数字符串
						    let urlStr = url.split('?')[1]
						    // 创建空对象存储参数
							let obj = {};
						    // 再通过 & 将每一个参数单独分割出来
							let paramsArr = urlStr.split('&')
							for(let i = 0,len = paramsArr.length;i < len;i++){
						        // 再通过 = 将每一个参数分割为 key:value 的形式
								let arr = paramsArr[i].split('=')
								obj[arr[0]] = arr[1];
							}
							return obj
						}
						uni.hideLoading()
						uni.navigateTo({
							url:`./register1?code=${getUrlParams(res.result).code}`
						})
					},
					fail(err) {
						// that.$ToastFail('Scan code failed, please try again')
					}
				})

			}
		}
	}
</script>

<style>
	.pages {
		padding: 0 40rpx;
		width: 100%;
		height: 100vh;
		overflow-y: auto;
		box-sizing: border-box;
	}

	.pages_title {
		font-family: Roboto;
		font-size: 24px;
		font-weight: 500;
		line-height: 24px;
		letter-spacing: 0em;
		text-align: left;
		margin-top: 40rpx;
	}

	.pages_tips {
		font-family: Roboto;
		font-size: 18px;
		font-weight: 500;
		line-height: 22px;
		letter-spacing: 0em;
		text-align: left;
		margin-top: 168rpx;
	}
</style>